package com.study.netty2;

import com.study.constant.Constants;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * @author mjy
 * @date 2021/12/07
 * @description(空闲检测处理，如果说多少秒没读到关闭管道连接)
 */
public class ServerIdHandler extends IdleStateHandler {


    public ServerIdHandler() {
        super(Constants.READER_IDLE_TIME, 0, 0, TimeUnit.SECONDS);
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
        System.out.println(Constants.READER_IDLE_TIME + " 秒内没有读取到数据,关闭连接");
        //关闭管道
        // ChannelHandler.closeChannel(ctx.channel());
    }



}
